package com.sy.controller;

import com.sy.dto.PageBean;
import com.sy.entity.CheckHome;
import com.sy.entity.Homework;
import com.sy.entity.StudentHome;
import com.sy.service.StudentHomeService;
import com.sy.service.StudentService;
import com.sy.vo.HomeworkVo;
import com.sy.vo.StudentHomeVo;
import com.sy.vo.StudentHomeworkUpdateVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author:fma
 * @Date: 2021/10/12 13:22
 */
@RestController
public class StudentHomeContoller {
    @Autowired
    private StudentHomeService studentHomeService;

    /**
     * 获取全部作业状态
     */
    @RequestMapping(value = "allstatus",method = RequestMethod.GET)
    public List<StudentHome> getHomesState(Integer startLimit,Integer endLimit) {
        return studentHomeService.getHomesState(startLimit,endLimit);
    }

    /**
     * 获取当前学生的作业状态
     * 前端请求路劲  http://localhost:8888/status?sno=2&pageNo=&oageNum=
     */
    @RequestMapping(value = "status", method = RequestMethod.GET, params = {"sno","pageNo","pageNum"})
    public PageBean<StudentHome> getHomeStateBySno(@RequestParam("sno") Integer sno,
                                                @RequestParam("pageNo") Integer pageNo,
                                                @RequestParam("pageNum") Integer pageNum) {
        return studentHomeService.getHomeStateBySno(sno,pageNo,pageNum);
    }
    /**
     * 根据教师的完整姓名和模糊作业关键字或者发布时间进行查询
     * @param studentHomeVo 作业状态信息
     * @return 根据条件查询出的商品信息的分页结果
     *  请求路劲 http://localhost:8888/getHomeworks?tno=1001&title=&createDate=
     */
    @RequestMapping(value = "status", method = RequestMethod.POST)
    public PageBean<StudentHome> getStatusByConditions(@RequestBody StudentHomeVo studentHomeVo) {
        System.out.println(studentHomeVo);
        return studentHomeService.getStatusByConditions(studentHomeVo);
    }

    /**
     * @param tno        分类id
     * @param pageNo     页码
     *                   前端请求路劲  http://localhost:8888/homeworks/teacherIds?tno=
     * @Author 范富强
     * 获取当前id指定的作业并分页显示
     * * 根据教师的完整姓名和模糊作业关键字或者发布时间进行查询
     */
    @RequestMapping(value = "studentHomeworks/teacherIds", method = RequestMethod.GET, params = {"tno","title", "pageNo", "pageNum"})
    public PageBean<CheckHome> getStudentHomeworksByConditions(@RequestParam(value = "tno") Integer tno,
                                                               @RequestParam(name = "title", required = false) String title,
                                                               @RequestParam(name = "pageNo", required = false, defaultValue = "1") Integer pageNo,
                                                               @RequestParam(name = "pageNum", required = false, defaultValue = "5") Integer pageNum) {
        return studentHomeService.getHomeWorksByConditions3(tno, title, pageNo, pageNum);
    }
    /**
     * @param pageNo     页码
     * @Author 范富强
     * 获取当前id指定的作业并分页显示
     * * 根据教师的完整姓名和模糊作业关键字或者发布时间进行查询
     */
    @RequestMapping(value = "studentHomeworks/tno", method = RequestMethod.GET, params = {"limit", "pageNo", "pageNum","title"})
    public PageBean<CheckHome> getStudentHomeworksByConditions2(
                                                               @RequestParam(name = "limit") String limit,
                                                               @RequestParam(name = "pageNo", required = false, defaultValue = "1") Integer pageNo,
                                                               @RequestParam(name = "pageNum", required = false, defaultValue = "5") Integer pageNum,
                                                               @RequestParam(name = "title", required = false) String title) {
        return studentHomeService.getHomeWorksByConditions4(limit, pageNo, pageNum,title);
    }


    @RequestMapping(value = "studentHomeworks", method = RequestMethod.POST)
    public Boolean updateStudentHomeworks(@RequestBody StudentHomeworkUpdateVo updateHomework){

        return  studentHomeService.updateStudentHomework(updateHomework);
    }






}
